package com;

import com.entity.Classes;
import com.entity.Menu;
import com.entity.Orders;
import com.entity.User;
import com.handler.CharArrayTypeHandler;
import com.mapper.MenuMapper;
import com.mapper.UserMapper;
import com.ymx.darling.bean.entity.BeanInfoManager;
import com.ymx.darling.bean.entity.fill.EntityFillProcessor;
import com.ymx.darling.bean.entity.fill.FillEntity;
import com.ymx.darling.bean.sql.BoundSql;
import com.ymx.darling.bean.sql.Parameter;
import com.ymx.darling.bean.sql.Statement;
import com.ymx.darling.cursor.Cursor;
import com.ymx.darling.intercept.ExecutorInterceptMethods;
import com.ymx.darling.intercept.ExecutorInterceptor;
import com.ymx.darling.intercept.InterceptManager;
import com.ymx.darling.intercept.Invocation;
import com.ymx.darling.logicdelete.LogicDeleteManager;
import com.ymx.darling.session.Session;
import com.ymx.darling.session.SessionFactory;
import com.ymx.darling.session.SessionFactoryBuilder;
import com.ymx.darling.session.setting.Callable;
import com.ymx.darling.session.setting.QuerySetting;
import com.ymx.darling.type.CharacterHandler;
import com.ymx.darling.util.LambdaUtil;
import com.ymx.darling.wrapper.QueryWrapper;

import java.sql.JDBCType;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * @author 爱Java的小于
 */
public class Demo03 {
    public static void main(String[] args) {
        SessionFactory sessionFactory = SessionFactoryBuilder.build("darling.xml");
        try (Session session = sessionFactory.openSession()) {
            QuerySetting.setPage(2, 5);
            session.selectList(LinkedHashMap.class, "select * from menu").forEach(System.out::println);
        }
        /*
           逻辑删除 多表逻辑删除 忽略逻辑删除  100 200 300 200
           租户id 忽略租户id
           实体填充 插入填充 更新填充
           类型转换器 自定义类型转换器
           字段脱敏 字段侦听
           缓存设置
           关联查询 单字段关联查询 菜单递归查询 内嵌参数的设置
           wrapper拦截器 Executor(执行器)拦截器
           数据库方言 分页 常用函数 主键生成
         */
    }

}

@ExecutorInterceptMethods("queryList")
class MyExecutor implements ExecutorInterceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        long start = System.currentTimeMillis();
        // 添加分页参数
        Statement statement = (Statement) invocation.getArgs()[0];
        BoundSql boundSql = statement.getBoundSql();
        boundSql.setSql(boundSql.getSql() + " limit ?"); // 只取前三条数据
        boundSql.getRightParameters().add(3);

        // 执行sql
        Object result = invocation.proceed();

        long end = System.currentTimeMillis() - start;
        System.out.println("本次查询总共执行"+ end);

        return result;
    }
}
